<?php 
class Organization extends Controller{
	public $data 	= 	array();
	public function __construct()
	{
		parent::Controller();
		$this->load->helper('ckeditor');
		//Ckeditor's configuration
		$this->data['ckeditor'] = array(
		'id' 	=> 	'content',
		'path'	=>	'js/ckeditor',
		//Optionnal values
		'config' => array(
		'toolbar' 	=> 	"Full", 	//Using the Full toolbar
		'width' 	=> 	"550px",	//Setting a custom width
		'height' 	=> 	'100px',	//Setting a custom height
		),
		//Replacing styles from the "Styles tool"
		'styles' => array(
		//Creating a new style named "style 1"
		'style 1' => array (
		'name' 		=> 	'Blue Title',
		'element' 	=> 	'h2',
		'styles' => array(
		'color' 	=> 	'Blue',
		'font-weight' 	=> 	'bold'
		)
			),
		//Creating a new style named "style 2"
		'style 2' => array (
		'name' 	=> 	'Red Title',
		'element' 	=> 	'h2',
		'styles' => array(
		'color' 		=> 	'Red',
		'font-weight' 		=> 	'bold',
		'text-decoration'	=> 	'underline'
		)
			)
			)
			);
		$this->data['ckeditor_2'] = array(
		//ID of the textarea that will be replaced
		'id' 	=> 	'content_2',
		'path'	=>	'js/ckeditor',
		//Optionnal values
		'config' => array(
		'width' 	=> 	"750px",	//Setting a custom width
		'height' 	=> 	'150px',	//Setting a custom height
		'toolbar' 	=> 	array(	//Setting a custom toolbar
		array('Source','-','Save','NewPage','Preview','-','Templates'),
		array('Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'),
		array('Undo','Redo','-','Bold', 'Italic'),
		array('Underline', 'Strike'),
		array('Find','Replace','-','SelectAll','RemoveFormat'),
		array('NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'),
		array('JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
		array('Link','Unlink','Anchor'),
		array('Image','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'),
		array('Styles','Format','Font','FontSize'),
		array('TextColor','BGColor'),
		array('-','Maximize'),
		'/'
		)
			),
		//Replacing styles from the "Styles tool"
		'styles' => array(
		//Creating a new style named "style 1"
		'style 3' => array (
		'name' 		=> 	'Green Title',
		'element' 	=> 	'h3',
		'styles' => array(
		'color' 	=> 	'Green',
		'font-weight' 	=> 	'bold'
		)
			)
			)
			);
	}
	public function index()
	{
		//model
		$this->load->model('organization_model');	//load model.
		$data=$this->organization_model->setdata();	//load model->setdata() function.
		//load pagination class
		$this->load->library('pagination');

		$offset=$this->uri->segment(3);

        $limit=2;

        $this->db->limit($limit, $offset);
		
        $this->db->order_by("c_org_id", "desc"); 
		$this->db->join('membership','membership.member_id=content_of_organization.member_id');
		$this->db->join('organization','organization.org_id=content_of_organization.org_id');
		$query = $this->db->get('content_of_organization');

        $config['base_url'] = base_url().'/organization/index/';
        $config['total_rows'] = $this->db->count_all('content_of_organization');
        $config['per_page'] = $limit;
        $this->pagination->initialize($config);
        $paginator=$this->pagination->create_links();

        $data = array(
            'query' => $query,
            'paginator'=>$paginator,
			'title' => 'Organization - Main Page.',
			'navigator' => '&nbsp;&#8250;&nbsp;Organization Node'
        );
		//views
		$this->load->view('inc/organization/main_content',$data);	//load view two cols.
	}
	public function add_news()
	{
		$this->data["title"] = "Organization - Add News.";
		$this->data["topic"] = "Add news of Organization.";
		$this->data["navigator"] = "&nbsp;&#8250;&nbsp;Community of Practice Node&nbsp;&#8250;&nbsp;Add News";
		$this->load->view('inc/organization/add_news',$this->data);
	}
	
	function add_organization_news()
	{
		$this->load->model('organization_model');
		$data=$this->organization_model->add_organization_news();
		if($data)
		{
			echo "ok";
		}
		else
		{
			echo "false";
		}
	}
	
	function view_content_org_by_id($id)	//content by category organization id ex. css, cs
	{
		$data["title"] = "Organization - By Category";
		$data["id"] = $id;
		$data["navigator"] = "&nbsp;&#8250;&nbsp;Community of Practice Node&nbsp;&#8250;&nbsp;Categories New";
		$this->load->view('inc/organization/view_content_org_by_id',$data);
	}
	
	function view_details_by_id($id)	//view content details by id
	{
		$data["title"] = "Organization - News";
		$data["id"] = $id;
		$data["navigator"] = "&nbsp;&#8250;&nbsp;Community of Practice Node&nbsp;&#8250;&nbsp;News detail";
		$this->load->view('inc/organization/view_details_by_id',$data);
	}
	
	function delete_org_news_by_id($id)	//delete org news by id
	{
		$data["id"] = $id;
		$this->load->model('organization_model');
		$query = $this->organization_model->delete_org_news_by_id($id);
		if($query)
		{
			$path = base_url()."organization/";
			redirect($path);
		}
		else{
			echo "False!!";
		}
	}
	public function edit_news($id)	//load edit org new views
	{
		$this->data["id"] = $id;
		$this->data["title"] = "Organization - Edit News.";
		$this->data["topic"] = "Edit news of Organization.";
		$this->data["navigator"] = "&nbsp;&#8250;&nbsp;Community of Practice Node&nbsp;&#8250;&nbsp;News edit";
		$this->load->view('inc/organization/edit_news',$this->data);
	}
	
	function edit_org_news_by_id() //edit org news by id
	{
		$id = $this->input->post('c_org_id');
		$this->load->model('organization_model');
		$data = $this->organization_model->edit_org_news_by_id($id);
		if($data)
		{
			$path = base_url()."organization/";
			redirect($path);
		}
		else
		{
			echo "False";
		}
	}
}